package com.eastfair.venuebooking.service.impl;

import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.messagecenter.api.MsgServiceFeign;
import com.eastfair.messagecenter.dto.InnerSendDTO;
import com.eastfair.messagecenter.dto.SmsSendDTO;
import com.eastfair.venuebooking.service.VenueBookingMsgService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 系统消息 service.
 *
 * @author dqq
 * @date 2023 /2/16
 */
@Service
@Slf4j
public class VenueBookingMsgServiceImpl implements VenueBookingMsgService {

    @Resource
    private MsgServiceFeign msgServiceFeign;

    @Override
    public boolean sendSmsMsg(SmsSendDTO smsSendDTO) {
        log.info("sendSmsMsg - 发送短信, smsSendDTO={}", smsSendDTO);
        R result = msgServiceFeign.sendSmsMsg(smsSendDTO);
        if (!result.getIsSuccess()) {
            log.error("sendSmsMsg - 发送失败, result={}", result);
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        log.info("sendSmsMsg - 发送短信完成, result={}", result);
        return true;
    }

    @Override
    public boolean sendInnerInMsg(InnerSendDTO innerSendDTO) {
        log.info("sendInnerInMsg - 发送站内信, innerSendDTO={}", innerSendDTO);
        R result = msgServiceFeign.sendInnerInMsg(innerSendDTO);
        if (!result.getIsSuccess()) {
            log.error("sendInnerInMsg - 发送失败, result={}", result);
            throw BizException.wrap(result.getCode(), result.getMsg());
        }
        log.info("sendInnerInMsg - 发送站内信完成, result={}", result);
        return true;
    }
}